package com.shyroke.daydayzhuanapi.mapper;

import cn.hutool.core.date.DateUtil;
import com.shyroke.daydayzhuanapi.dto.CommentDto;
import com.shyroke.daydayzhuanapi.entity.CommentEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CommentMapper {
    @Autowired
    private ModelMapper modelMapper;

    public CommentEntity dtoToEntity(CommentDto comment) {
        return modelMapper.map(comment,CommentEntity.class);
    }

    public CommentDto entityToDto(CommentEntity e) {
        CommentDto comment = modelMapper.map(e, CommentDto.class);
        comment.setProjectId(e.getProject().getId());
        comment.setShowCreateTime(DateUtil.format(comment.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
        return comment;
    }
}
